<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:core="http://www.contact.core.com/contacts/core/ui"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:common="http://www.contact.common.com/contacts/ui"
        >

<!--@elvariable id="id" type="java.lang.String"-->
<ui:component>


    <h:panelGrid id="#{id}addressPanelGrid" style="background:inherit" columns="1">
        <h:panelGroup style="float:left;" layout="block">
            <h:panelGroup style="float:left">
                <h:outputLabel value="#{resources.addressLabel}"/>
            </h:panelGroup>
            <h:panelGroup style="margin-left:5px">
                <!--value="Add"-->
                <a4j:commandButton image="./style/images/add.PNG"
                                   action="#{contactInformation.addNewAddressRow}"
                                   reRender="#{id}richTableForAddresst">
                    <rich:toolTip direction="bottom-right" value="#{resources.addLabel}"/>
                </a4j:commandButton>
                <!--<a4j:commandLink value="Add"-->
                <!--action="#{contactInformation.addNewAddressRow}"-->
                <!--reRender="#{id}richTableForAddresst">-->
                <!--</a4j:commandLink>-->
            </h:panelGroup>
        </h:panelGroup>
        <h:panelGroup id="#{id}richTableForAddresst"
                      rendered="#{not empty contactInformationSessionBean.allAdresses}"
                      layout="block"
                      style="float:left;">
            <rich:dataTable style="background:inherit" cellpadding="0"
                            value="#{contactInformationSessionBean.allAdresses}" var="data">


                <rich:column>
                    <h:panelGrid columns="2">
                        <h:panelGrid columns="2">
                            <h:outputLabel rendered="#{contactInformation.configureMainAddress}"
                                           value="#{resources.setMainLabel}"/>
                            <h:selectBooleanCheckbox rendered="#{contactInformation.configureMainAddress}"
                                                     value="#{data.checkedRow}">
                                <a4j:support event="onchange"
                                             action="#{contactInformation.singleChecked}"
                                             reRender="#{id}richTableForAddresst">
                                    <f:param value="#{data.index}" name="mainAddressIndex"/>
                                </a4j:support>
                            </h:selectBooleanCheckbox>

                            <h:outputLabel
                                    rendered="#{data.checkedRow and not contactInformation.configureMainAddress}"
                                    value="#{resources.mainAddressLabel}"/>
                            <h:selectBooleanCheckbox
                                    rendered="#{data.checkedRow and not contactInformation.configureMainAddress}"
                                    value="#{data.checkedRow}"/>

                            <h:outputLabel value="#{resources.addressLabel}"/>
                            <h:inputText value="#{data.address.address}"/>

                            <h:outputLabel value="#{resources.cityTownLabel}"/>
                            <h:inputText value="#{data.address.city}"/>

                            <h:outputLabel value="#{resources.neighbordHoodLabel}"/>
                            <h:inputText value="#{data.address.neighborhood}"/>

                            <h:outputLabel value="#{resources.zipLabel}"/>
                            <h:inputText value="#{data.address.zip}"/>


                        </h:panelGrid>
                        <!--<a4j:commandLink rendered="#{data.existsRemoveLink}"-->
                        <!--value="Remove"-->
                        <!--action="#{contactInformation.removeAddressRow}"-->
                        <!--reRender="#{id}richTableForAddresst">-->
                        <!--<f:param value="#{data.index}" name="addressIndex"/>-->
                        <!--</a4j:commandLink>-->
                        <!--value="Remove"-->
                        <a4j:commandButton rendered="#{data.existsRemoveLink}"
                                           image="./style/images/remove.PNG"
                                           action="#{contactInformation.removeAddressRow}"
                                           reRender="#{id}richTableForAddresst"
                                >
                            <rich:toolTip direction="bottom-right" value="#{resources.removeLabel}"/>
                            <f:param value="#{data.index}" name="addressIndex"/>
                        </a4j:commandButton>
                    </h:panelGrid>

                </rich:column>

                <!--<rich:column>-->
                <!--<f:facet name="header">-->
                <!--<h:outputLabel value="Operation"/>-->
                <!--</f:facet>-->
                <!---->

                <!--</rich:column>-->

            </rich:dataTable>
        </h:panelGroup>

        <h:panelGroup rendered="#{contactInformation.configureMainAddress}">
            <a4j:commandLink
                    value="#{resources.saveConfigurationLabel}"
                    action="#{contactInformation.closeConfigureMainAddress}"
                    reRender="#{id}addressPanelGrid"
                    />

        </h:panelGroup>
        <h:panelGroup rendered="#{not contactInformation.configureMainAddress}">
            <a4j:commandLink
                    value="#{resources.configureMainAddressLabel}"
                    action="#{contactInformation.openConfigureMainAddress}"
                    reRender="#{id}addressPanelGrid"
                    />


        </h:panelGroup>


    </h:panelGrid>
</ui:component>


</html>
